<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2016-6-21
 * Func   文章分类管理
 */
defined('IN_YuLin') || exit('NO PERMIT!');

$table = Table('article_category');

if(IS_POST)
{
    $id = intval($_REQUEST['id']);
    $data = $id ? $db->getrow('SELECT * FROM '.$table.' WHERE id = '.$id) : [];

    $ins = [];
    $ins['title']    	=   NoBadStr($_POST['title']);
    $ins['listsort']	=   intval($_POST['listsort']);

	if($data['id'])
	{
        //修改
        $db->exec('UPDATE '.$table.' SET '.CreateUpdateSql($ins).' WHERE id = '.$data['id']);
    }
	else
	{
		$ins['dateline']=   TIMESTAMP;
        $db->exec('INSERT INTO '.$table.CreateInsertSql($ins));
    }
	
    AjaxReturn(['error'=>'0','msg'=>'操作成功']);
}

if($a == 'add')
{
    $id = intval($_GET['id']);
    $data = $id ? $db->getrow('SELECT * FROM '.$table.' WHERE id = '.$id) : [];
    
    $tpl->display($m.'/category_add');
}
else if($a == 'del')
{
    $id = intval($_GET['id']);
	$id && $db->exec('DELETE FROM '.$table.' WHERE id = '.$id);
	
    AjaxReturn(['error'=>'0','msg'=>'删除成功']);
}
else
{
    $data  = $db->getall('SELECT t.* FROM '.$table.' t ORDER BY t.listsort DESC');

    $tpl->display($m.'/category');
}